package com.bj58.ecdata.dashboard.controllers;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import com.bj58.ecdata.dashboard.cache.ServiceBeanFactory;
import com.bj58.ecdata.dashboard.constant.EnumCate;
import com.bj58.ecdata.dashboard.databll.PriviledgeBLL;
import com.bj58.ecdata.dashboard.dbentity.IncomeCity;
import com.bj58.ecdata.dashboard.service.AbstractBaseService;
import com.bj58.ecdata.dashboard.utils.MyServletRequestUtils;
import com.bj58.groupbuy.action.interceptors.Check;
import com.bj58.groupbuy.action.model.User;
import com.bj58.groupbuy.action.util.SomePublicUtil;
import com.bj58.wf.mvc.ActionResult;
import com.bj58.wf.mvc.BeatContext.Model;
import com.bj58.wf.mvc.MvcController;
import com.bj58.wf.mvc.annotation.GET;
import com.bj58.wf.mvc.annotation.POST;
import com.bj58.wf.mvc.annotation.Path;

@Path("/customer")
public class CustomerController extends MvcController {
	private SomePublicUtil spu = new SomePublicUtil();
	private AbstractBaseService<IncomeCity> imCityService = ServiceBeanFactory.get(IncomeCity.class,null);
	
	/**
	 * 余额客户看板
	 * @return
	 * @author houzuoxin 2015-06-19
	 */
	@Path({"/balancecs"})
	@Check("dashboard/customer/balancecs")
	@GET
	@POST
	public ActionResult dashboard() {
		EnumCate cateEnum = null;
		try {
			HttpServletRequest request = beat.getRequest();
			User user = spu.getUserByCookie(request);
			//检查业务线权限
			String businessOperStr = PriviledgeBLL.businessOperCheck(user);
			
			String[] businessOpers = businessOperStr.split(",");
			
			String businessName = MyServletRequestUtils.getStringParameter(request, "businessName","total");
			
			if("total".equals(businessName)){
				businessName="zhaopin";
				cateEnum = EnumCate.valueOf(businessName);
			}else{
				cateEnum = EnumCate.valueOf(businessName);
			}
			
			if("total".equals(businessOpers[0])){
				businessOpers = Arrays.copyOfRange(businessOpers, 1, businessOpers.length);
			}
			//目前的最大日期
			String maxDate = imCityService.getMaxDate();
			Model model = beat.getModel();
			model.add("maxDate", maxDate);
			//业务线 中英文名
			model.add("businessName", businessName);
			model.add("businessName_CN", cateEnum.getDBName());
			model.add("business_CN_Map",EnumCate.business_CN_Map);
			//业务线权限
			model.add("businessList",businessOpers);
		} catch (Exception e) {
			log.error(null, e);
			return ActionResult.view("null");
		}
		return ActionResult.view("customer/balancecs");
	}
}
